<script src="<?php echo URL::base() ?>media/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript">

    function checkForm() {

        if (form1.sku.value == '') {

            alert('SKU不能为空！');
            //form1.sku.focus();
            return false;
        }

        if (form1.sku_name.value == '') {
            alert('SKU名称不能为空！');
            form1.sku_name.focus();
            return false;
        }
        var count = form1.sku_quality.value;
        var count = Number(count);
        if (isNaN(count)) {

            alert('数量格式非法！');
            form1.sku_quality.focus();
            return false;
        }
        if (count < 1) {
            alert('数量不能为0！');
            form1.sku_quality.focus();
            return false;
        }
        var quality = form1.sku_quality.value;
        if (/^\d+$/.test(quality)) {

        } else {
            alert('数量不能有小数！');
            form1.sku_quality.focus();
            return false;
        }

        if (form1.remarks.value == '') {
            alert('不合格原因不能为空！');
            form1.remarks.focus();
            return false;
        }

    }

    function getname() {
        var sku = $('#sku').val();
        if (sku == '') {
            alert('SKU不能为空！');
            return false;
        }
        $.ajax(
            {
                type: 'post',
                url: '<?php echo url::base(TRUE)?>quality/getSkuInfo',
                dataType: 'json',
                data: {"sku": sku},
                async: false,
                success: function (re_data) {
                    console.log(re_data);
                    if (re_data) {
                        $("#sku_name").val(re_data.chineseProductName);
                        $('#sku_name').attr("readonly","readonly");
                        $('#pur_name').val("<?php echo $user->nick?>");
                        $('#pur_name').attr("readonly","readonly");
                        $('#sku_unit').val(re_data.unit);
                        $('#sku_unit').attr("readonly","readonly");


                    }else{
                        alert('sku不存在');
                    }
                },
                error: function () {
                }
            }
        );

    }

</script>

<body id="pageContent" class="well">
<div class="container-fluid">
    <div class="row">
     <form class="form-horizontal" action="<?php echo url::base(TRUE) ?>quality/addunquality" method="post"
                  name="form1" onsubmit="return checkForm();">
         <div class="control-group">
            <label class="control-label" for="input01">SKU:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" onBlur="getname()" name="sku" id="sku" value=""/>

            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="input01">中文名称:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="sku_name" id="sku_name" value=""/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="input01">计划员:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="pur_name" id="pur_name" value=""/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="input01">数量:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="sku_quality" id="sku_quality" value=""/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="input01">规格:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="sku_unit" id="sku_unit" value=""/>
            </div>
        </div>
        <div class="control-group">

            <!-- Textarea -->
            <label class="control-label">质检不合格原因:</label>
            <div class="controls">
                <div class="textarea">
                    <textarea type="" class="" style="margin: 0px; width: 272px; height: 117px;resize:none;"
                              name="remarks" id="remarks"></textarea>
                </div>
            </div>
        </div>
            <div class="control-group">
                <!-- Button -->
                <div class="controls">
                    <button class="btn btn-info" id="addsubnit_ids" onclick="return getname();">提交</button>
                    <input type="reset" name="set" class="btn btn-default" value="重置"/>
                </div>
            </div>

      </form>
    </div>
</div>
</body>
 
